The first character in a string is at index 0.
public static String slice(String s) {
String c = s.substring(0, 1);
return c;
}
| Function Call | Return Value | |||
|---|---|---|---|---|
| slice("Car") | → | |||
| slice("Truck") | → | |||
| slice("55684") | → | |||
| slice("Elephant") | → | |||
| slice("Roses") | → | |||
Experiment with this code on Gitpod.io